<?php
session_start();
include_once("./configs/configs.php");
include_once("./common/mysql.class.php");
//include_once('./common/action.class.php');
$db = new mysql($mydbhost, $mydbuser, $mydbpw, $mydbname, ALL_PS, $mydbcharset);
include_once './common/imageUpload.class.php';
include_once './common/page.class.php';
include_once './common/weibooauth.php';
/************************************************************************/
    /*
   * 获取博客信息
   */
  $sql="select * from `user`;";
  $result=$db->query($sql);
  $myinfo=$db->fetch_assoc($result);
  static $logined=false;
  if($_SESSION['user_name']==$myinfo['user_name']&&$_SESSION['user_pwd']==$myinfo['user_pwd']){
  	$logined=true;
  }
  /*
   * 读取session，是否已经用新浪微博登录
   */
  static $sinalogined=false;
  static $me=array();
  if(isset($_SESSION['last_key']['oauth_token'])&&isset($_SESSION['last_key']['oauth_token'])){
  	  $sinalogined=true;
  	  $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret']);
      $me = $c->verify_credentials();
      $smarty->assign('me',$me);//输出微博个人信息
      if((string)$_SESSION['last_key']['oauth_token']==$token&&(string)$_SESSION['last_key']['oauth_token_secret']==$secret){
           $logined=true;
      }
  }
  if($_GET['out']==1){
  	unset($_SESSION['user_name'],$_SESSION['user_pwd']);
	unset($_SESSION['last_key']['oauth_token'],$_SESSION['last_key']['oauth_token_secret']);
  	$logined=false;
  	$sinalogined=false;
  	echo "<script>alert('已退出登录！');location.href='index.php'</script>";
  }
   
  //print_r($myinfo);
  /************************************************************************/
  /*
   * 获取用户签名
   */
  $sql="SELECT * FROM `signature` ORDER BY `signID` DESC limit 1";
  $result=$db->query($sql);
  $signature=$db->fetch_assoc($result);
  //print_r($signature);
  
  /************************************************************************/
  $smarty->assign('sinalogined',$sinalogined);//新浪微博登录标志
  $smarty->assign('logined',$logined);//系统自带账户登录标志
  $smarty->assign('weiboID',$weiboID);
  $smarty->assign('myinfo',$myinfo);
  $smarty->assign('signature',$signature);
?>